﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zwms.Client.CommonUI;
using grproLib;
using Zwms.Client.Helper;
using Zwms.Data.BusinessObjects;

namespace Zwms.Client.InWms
{
    public partial class PrintBarCodeAssistForm : BaseForm
    {
        GridppReport Report = new GridppReport();
        private IGRField _barCodeField;
        private IGRField _goodsNameField;
        private string _sDatetime;
        private IList<BilInPlanBillDetail> _inPlanBillDetailList;

        public PrintBarCodeAssistForm(IList<BilInPlanBillDetail> inPlanBillDetailList, string dt)
        {
            InitializeComponent();
            _sDatetime = dt;
            _inPlanBillDetailList = inPlanBillDetailList;
            Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(ReportInitialize);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);
            Report.LoadFromFile(Application.StartupPath + string.Format("\\Reports{0}", StringHelper.sBarcodeLabel));

            Report.PrintPreview(true);
            
        }

        private void ReportInitialize()
        {
            _barCodeField = Report.FieldByName("BarCode");
            _goodsNameField = Report.FieldByName("GoodsName");
        }

        private void ReportFetchRecord()
        {
            foreach (BilInPlanBillDetail record in _inPlanBillDetailList)
            {
                Report.DetailGrid.Recordset.Append();
                _barCodeField.AsString = string.Format("{0}#{1}", record.GoodsCode, _sDatetime);
                _goodsNameField.AsString = record.GoodsName;
                Report.DetailGrid.Recordset.Post();
            }
        }

        private void PrintBarCodeAssistForm_Load(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
